package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pojo.Lunbo;
import service.LunboService;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/lunbo")
public class LunboController {

    @Autowired
    private LunboService lunboService;

    @PostMapping("/add")
    public int addLunbo(@RequestBody Lunbo lunbo) {
        return lunboService.add(lunbo);
    }

    @GetMapping("/enabled")
    public List<Lunbo> findEnabled() {
        return lunboService.findEnabled();
    }

    @GetMapping("/all")
    public List<Lunbo> findAll() {
        return lunboService.findAll();
    }

    @GetMapping("/{id}")
    public Lunbo findById(@PathVariable Integer id) {
        return lunboService.findById(id);
    }

    @PutMapping("/update")
    public int updateLunbo(@RequestBody Lunbo lunbo) {
        return lunboService.update(lunbo);
    }

    @DeleteMapping("/{id}")
    public int deleteById(@PathVariable Integer id) {
        return lunboService.deleteById(id);
    }
}